import loadComponents from 'components/index'
import { Notify } from 'quasar'
import { defineBoot } from '#q-app/wrappers'
import loadDirectives from 'src/directives'

export default defineBoot(({ app }) => {
  const env = import.meta.env
  app.config.globalProperties.isDEV = env.DEV
  app.config.globalProperties.$tooltipAttr = {
    transitionShow: 'jump-down', transitionHide: 'jump-up',
    class: 'qx-tooltip overflow-hidden text-caption q-pa-md shadow-8',
    maxWidth: '35vw', offset: [0, 8], delay: 800
  }
  app.config.globalProperties.$thumbStyle = { zIndex: 2001 }
  app.config.globalProperties.$barStyle = {}

  Notify.registerType('primary', { classes: 'q-primary-msg', textColor: 'primary', color: 'white', icon: 'info' })
  Notify.registerType('warning', { classes: 'q-warning-msg', textColor: 'warning', color: 'white', icon: 'error' })
  Notify.registerType('negative', { classes: 'q-error-msg', textColor: 'negative', color: 'white', icon: 'cancel' })
  Notify.registerType('positive',
    { classes: 'q-positive-msg', textColor: 'positive', color: 'white', icon: 'check_circle' })

  app.config.errorHandler = (err, vm, info) => {
    // 处理错误，例如：报告给一个服务
    console.error('[全局异常]', err, vm, info)
  }

  app.config.warnHandler = (msg, instance, trace) => {
    // `trace` is the component hierarchy trace
    if (msg && msg.startsWith('Failed to resolve component: iconpark-icon')) return
    console.warn('[全局警告]', msg, instance, trace)
  }

  loadComponents(app)
  loadDirectives(app)
})